﻿using System.Windows.Forms;
using ApplicationLibrary;
using ApplicationLibrary.DBManager;
using ApplicationLibrary.ExtendedControls;
using ApplicationLibrary.Preferences;
using Plumber.Accounting.Forms;
using Plumber.Accounting.ModuleData;
using Plumber.Accounting.Preferences;
using Plumber.Masters.ModuleData;
using Plumber.Sales.ModuleData;

namespace Plumber.Accounting.Scrounger
{
    public partial class TabLiquidationType : UserControl, iScroungerUserControl
    {
        private const string LiquidationTypeSlave = "LIQUIDATIONTYPESLAVE";
        private Masters.Forms.Company companyForm = null;
        private EnumsManager<LiquidationType> eType = null;

        public TabLiquidationType()
        {
            InitializeComponent();
        }

        public void OnAttachData(ApplicationLibrary.DBManager.DBManager dbManager)
        {
            ltc_Year.Items.Add(0);
            for (int t = 2011; t <= GlobalInfo.CurrentDate.Year; t++)
                ltc_Year.Items.Add(t);

            eType = new EnumsManager<LiquidationType>(ltc_Type, true);

            dgwLT.AutoGenerateColumns = false;
            dgwLT.DataSource = dbManager.Dataset.Tables[PL_LiquidationType.Name];
        }

        public void OnBindData(ApplicationLibrary.DBManager.iScrounger frm)
        {
            DocumentForm doc = (DocumentForm)frm;
            if (frm.GetType() != typeof(Masters.Forms.Company))
                return;

            this.companyForm = (Masters.Forms.Company)frm;
            doc.BindControl(dgwLT);
            doc.BindColumn(ltc_Year, PL_LiquidationType.Year);
            doc.BindColumn(ltc_Type, PL_LiquidationType.Type);
        }

        public void AutoResizeColumns()
        {
            dgwLT.AutoResizeColumns();
        }

        public void OnPrepareAuxData()
        {
        }
    }
}